<?php $this->load->view('common/default_header.php');?>
<?php $this->load->view('common/nav.php');?>
<section class="trade">
    <div class="panels">
        <div class="l icon1">
            <h5><?php echo $user_info['nickname'];?></h5>
            <b><?php echo hideStr($user_info['phone'],3,4,4)?></b>
        </div>
        <div class="r icon2">
            <h5>帐户余额(元)</h5>
            <b><?php echo $user_info['cny'];?></b>
        </div>
        <div class="clear"></div>
    </div>
    <div class="" style="padding: 0 10px;">
        <input class="form-control hm" type="text" id="amount" name="amount" placeholder="请输入充值金额"/>
        <label>到账金额：<span id="actual">0</span>元</label>
        <div class="text-center borbtm">
            <a class="btn button btn-warning" href="javascript:changeAmount(20)">20元</a>
            <a class="btn button btn-warning" href="javascript:changeAmount(50)">50元</a>
            <a class="btn button btn-warning" href="javascript:changeAmount(100)">100元</a>
            <a class="btn button btn-warning" href="javascript:changeAmount(200)">200元</a>
            <a class="btn button btn-warning" href="javascript:changeAmount(500)">500元</a>
            <a class="btn button btn-warning" href="javascript:changeAmount(1000)">1000元</a>
        </div>
        <div class="check-type">
            <p onclick="changePay('wxDeposit',this)" style="cursor: pointer;"><span class="checkbox_icon check-on"></span>微信钱包付款</p>
            <input type="hidden" id="payType" value="wxDeposit">
        </div>
        <div class='cc'>
            <a href="javascript:deposit(this);" class="btn btn-danger btn-lg btn-block" id="depositBtn">立即充值</a>
        </div>

    </div>
    <div style="display: none" id="bankDepositHtml"></div>
</section>

<script src="<?php echo js_url("/wcp/jquery-1.9.1.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/bootstrap.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/main.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/bootstrap-dialog.min.js"); ?>?20160329001" type="text/javascript"></script>
<?php $this->load->view('common/wx_share.php');?>
<script type="text/javascript">
 

function changePay(type,obj){
    $('.checkbox_icon').removeClass('check-on');
    var payClass = $(obj).children('span').attr('class');
    if (payClass.indexOf('check-on')< 0) {  
        $(obj).children('span').addClass('check-on');
    }
    $('#payType').val(type);
}

function changeAmount(amount){
    $('#amount').val(amount);
    $('#actual').html(accMul(amount,0.992));
}

function deposit(btnEle){
    var payType = $('#payType').val();
    var amount = $('#amount').val();
    if(amount<=0){
        myAlert("请输入充值金额");
        return;
    }
    if(amount<20){
        myAlert("充值金额不能少于20元");
        return;
    }

    var disable = $('#depositBtn').hasClass('disabled');
    if ((disable == false || disable == undefined)) {
        $('#depositBtn').addClass('disabled');
        if(payType=='wxDeposit'){//微信支付
            $.ajax({
                type: 'POST',
                url: "/cny/wxDeposit",
                dataType: 'json',
                data: {'amount': amount} ,
                beforeSend: function(){
                    $('#depositBtn').html('加载中...');
                },
                success: function(data){
                    if(data.errno==0){
                            wx.chooseWXPay({
                                appId: data.data.appId, // 必填，公众号的唯一标识
                                timestamp: data.data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                                nonceStr: data.data.nonceStr, // 支付签名随机串，不长于 32 位
                                package: data.data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
                                signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                                paySign: data.data.paySign, // 支付签名
                                success: function (res) {
                                    if(res.err_msg == "get_brand_wcpay_request:ok") {
                                        
                                    }

                                    $('#depositBtn').html('立即充值');
                                    $('#depositBtn').removeClass('disabled');
                                },
                                cancel:function(res){
                                    $('#depositBtn').html('立即充值');
                                    $('#depositBtn').removeClass('disabled');
                                }
                            });
                        wx.error(function(res){
                            $('#depositBtn').html('立即充值');
                            $('#depositBtn').removeClass('disabled');
                        });     
                    }else{
                        myAlert(data.msg);
                        $('#depositBtn').html('立即充值');
                        $('#depositBtn').removeClass('disabled');
                    }
                }
            });
        }else{//银行支付
           $.ajax({
                type: 'POST',
                url: "/api/cny/deposit",
                data: {'amount': amount} ,
                beforeSend: function(){
                    $('#depositBtn').html('加载中...');
                },
                success: function(data){
                    $('#bankDepositHtml').html(data);
                }
            });
        }
    }
}


</script>

